package com.example.util;

import cn.hutool.crypto.Mode;
import cn.hutool.crypto.Padding;
import cn.hutool.crypto.symmetric.AES;

//糊涂工具包 - 工具类，用来处理中文乱码

public class PwdUtil {
    // key：AES模式下，key必须为16位
    private static String key = "1234567812345678";
    // iv：偏移量，ECB模式不需要，CBC模式下必须为16位
    private static String iv = "1234567812345678";
    /**
     * 加密
     * @param text
     * @return
     */
    public static String encoder(String text){

        // AES aes = new AES(Mode.ECB, Padding.PKCS5Padding, key.getBytes());
        AES aes = new AES(Mode.CBC, Padding.PKCS5Padding, key.getBytes(), iv.getBytes());
        // 加密并进行Base转码
        String encrypt = aes.encryptBase64(text);
        return encrypt;
    }

    public static String decoder(String encrypt){
        AES aes = new AES(Mode.CBC, Padding.PKCS5Padding, key.getBytes(), iv.getBytes());
        String decrypt = aes.decryptStr(encrypt);
        return decrypt;
    }
}
